package com.woniuxy.food.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.cloud.mall95.log.Log;
import com.woniuxy.food.client.foodspuclient.FoodSpuManageClient;
import com.woniuxy.food.client.param.InsertFoodSpuParam;
import com.woniuxy.food.client.param.UpdateFoodSpuParam;
import com.woniuxy.food.client.param.UpdateFoodSpuSalesCountParam;
import com.woniuxy.food.client.param.UpdateFoodSpuStateParam;
import com.woniuxy.food.service.FoodSpuService;
import com.woniuxy.food.service.serviceparam.InsertFoodSpuServiceParam;
import com.woniuxy.food.service.serviceparam.UpdateFoodSpuSalesCountServiceParam;
import com.woniuxy.food.service.serviceparam.UpdateFoodSpuServiceParam;
import com.woniuxy.food.service.serviceparam.UpdateFoodSpuStateServiceParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

@RestController
@Slf4j
public class FoodSpuManageClientApiImpl implements FoodSpuManageClient {
    @Autowired
    private FoodSpuService foodSpuService;

    @Override
    @Log("添加菜品spu")
    public Result insertFoodSpu(InsertFoodSpuParam param) {
        InsertFoodSpuServiceParam insertFoodSpuServiceParam = BeanUtil.toBean(param, InsertFoodSpuServiceParam.class);
        foodSpuService.insertFoodSpu(insertFoodSpuServiceParam);
        return Result.success();
    }

    @Override
    @Log("菜品spu上下架")
    public Result updateFoodSpuStateByIds(UpdateFoodSpuStateParam param) {
        UpdateFoodSpuStateServiceParam updateFoodSpuStateServiceParam = BeanUtil.toBean(param, UpdateFoodSpuStateServiceParam.class);
        foodSpuService.updateFoodSpuStateByIds(updateFoodSpuStateServiceParam);
        return Result.success();
    }

    @Override
    @Log("根据ID修改菜品spu信息")
    public Result updateFoodSpuById(UpdateFoodSpuParam param) {
        UpdateFoodSpuServiceParam updateFoodSpuServiceParam = BeanUtil.toBean(param, UpdateFoodSpuServiceParam.class);
        foodSpuService.updateFoodSpuById(updateFoodSpuServiceParam);
        return Result.success();
    }

    @Override
    @Log("根据ID修改菜品spu总销量")
    public Result updateFoodSpuSalesCountById(UpdateFoodSpuSalesCountParam param) {
        UpdateFoodSpuSalesCountServiceParam updateFoodSpuSalesCountServiceParam = BeanUtil.toBean(param, UpdateFoodSpuSalesCountServiceParam.class);
        foodSpuService.updateFoodSpuSalesCountById(updateFoodSpuSalesCountServiceParam);
        return Result.success();
    }

    @Override
    @Log("根据ID删除菜品spu")
    public Result deleteFoodSpuByIds(Integer storeId, Integer[] ids) {
        foodSpuService.deleteFoodSpuByIds(storeId,ids);
        return Result.success();
    }
}
